// 工具库文件,提供一些公用js方法
import routes from '@/config/routes.config.js';
import * as $apis from '@/apis/index.js';
import store from '@/store/index.js';
import dataFunction from '@/common/data_function/index.js'
import $mRouter from '@/common/router.js'
export default {
	// 复制文字
	copyText(text,tip){
		uni.setClipboardData({
		    data: text,
		    success: function () {
		        uni.showToast({
		        	title: tip || '复制成功',
					icon: 'none',
					duration: 2000
		        })
		    }
		});
	},
    // 计算两个时间戳之间差几天
    getDayD(start,end){
        let utc = end - start;
        let d = parseInt(utc/(24*60*60));
        let i = parseInt(utc/(60*60));
        let s = parseInt(utc/(60));
        return {
            d,
            i,
            s
        }
    },
    // canvas左右居中计算
    canvasCenter(allWidth,onlyWidth){
        let width1 = allWidth / 2;
        let width2 = onlyWidth / 2;
        let start = (width1 - width2);
        return start
    },
    // 动态创建a链接并点击
    createA(href){
		// #ifdef H5
		var a = document.createElement('a');
		a.setAttribute('href', href);
		document.body.appendChild(a);
		a.click();
		// #endif
    },
    // 检测终端ios，安卓
    isAndroid(){
        var u = navigator.userAgent;
        var android = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        var iOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if(android){
            return true
        }else{
            return false
        }
    },
    // 图片预览
    lookImg(urls) {
        uni.previewImage({
            urls: urls
        });
    },
    // 解析地址栏参数
    UrlParamHash(url) {
        var params = {},
            h;
        var hash = url.slice(url.indexOf("?") + 1).split('&');
        for (var i = 0; i < hash.length; i++) {
            h = hash[i].split("="); //
            params[h[0]] = h[1];
        }
        return params;
    },
    // 图片转base64
    image2Base64(img) {
        var canvas = document.createElement("canvas");
        canvas.width = img.width / 3;
        canvas.height = img.height / 3;
        var ctx = canvas.getContext("2d");
        ctx.drawImage(img, 0, 0, img.width / 3, img.height / 3);
        var dataURL = canvas.toDataURL("image/png");
        return dataURL;
    },
    getImgBase64(src) {
        var base64 = "";
        var img = new Image();
        img.src = src;
        return new Promise((resolve, reject) => {
            img.onload = () => {
                base64 = this.image2Base64(img);
                resolve(base64)
            }
        })
    },
    // 监听系统返回键
    getBack() {
        if (getCurrentPages().length > 1) {
            return
        }
        let routerName = ''
        let routerQuery = ''
        let query = {}
        // console.log(window.location)
        let url = window.location.pathname + window.location.search
        for(let i in routes){
            if(routes[i].path == window.location.pathname){
                routerName = i
            }
        }
        if(window.location.pathname == '/'){
            routerName = 'index'
        }
        if(window.location.search){
            routerQuery = window.location.search.substr(1).split('&')
            for(let i in routerQuery){
                query[routerQuery[i].split('=')[0]] = routerQuery[i].split('=')[1]
            }
        }
        $mRouter.redirectTo({
            route: routes['index']
        })
        $mRouter.redirectTo({
            route: routes[routerName],
            query
        })
        if(routerName){
            return
        }
        uni.navigateTo({
            url: url
        });
    },
    // 设置路径
    pushHistory(title, url) {
        var state = {
            title: title,
            url: url
        };
        window.history.pushState(state, state.title, state.url);
    },
    // 清除cookies
    clearCookie(name) {
        this.setCookie(name, "", -1);
    },
    // 设置cookies
    setCookie(cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
        var expires = "expires=" + d.toUTCString();
        document.cookie = cname + "=" + cvalue + "; " + expires;
    },
    // 获取cookies
    getCookie(name) {
        var strcookie = document.cookie; //获取cookie字符串
        var arrcookie = strcookie.split("; "); //分割
        //遍历匹配
        for (var i = 0; i < arrcookie.length; i++) {
            var arr = arrcookie[i].split("=");
            if (arr[0] == name) {
                return arr[1];
            }
        }
        return "";
    },
	//多图保存
	saveImgs(imgArr){
		return new Promise((resolve, reject)=>{
			let promiseArr = [];
			for(let i = 0; i < imgArr.length; i ++){
				promiseArr.push(this.saveImg(imgArr[i],true))
			}
			Promise.all(promiseArr).then((res)=>{
				uni.hideLoading();
				resolve(res);
			}).catch((err)=>{
				console.log(err);
				uni.hideLoading();
			})
		})
	},
    //保存图片到相册
    saveImg(url,noLoad) {
        return new Promise((resolve, reject) => {
            // #ifdef H5
            uni.showToast({
                title: '请长按图片，保存到相册',
                icon: 'none',
                duration: 5000
            })
            return
            // #endif
			uni.showLoading({
				title: '保存图片中'
			})
            uni.saveImageToPhotosAlbum({
                filePath: url,
                success(res) {
					if(!noLoad){
						uni.hideLoading();
					}
                    resolve(res);
                },
                fail(error) {
                    uni.downloadFile({
                        url: url,
                        success(res) {
                            if (res.statusCode === 200) {
                                uni.saveImageToPhotosAlbum({
                                    filePath: res.tempFilePath,
                                    success(res) {
                                        resolve(res);
                                    },
                                    fail(error) {
                                        uni.showModal({
                                            content: '保存失败，请检查权限！'
                                        })
                                        reject(error);
                                    },
                                    complete() {
										if(!noLoad){
											uni.hideLoading();
										}
                                    }
                                })
                            }
                        },
                        fail(error) {
							if(!noLoad){
								uni.hideLoading();
							}
                            uni.showModal({
                                content: '下载失败，请检查网络！'
                            })
                            reject(error)
                        }
                    })
                },
                complete() {
					
                }
            })
        })
    },
    //解析扫码参数
    deleteamp(obj) {
        if (!obj) return false;
		let {query,path} = obj;
		if(path.indexOf('/') != 0){
			path = '/' + path
		}
		$mRouter.push({route: routes[this.jxUrlName(path)],qeury: {...query}});
        // if (obj.scene) { //如果通过扫码
        //     let params = decodeURIComponent(obj.scene).split("&");
        //     let res = {}
        //     params.forEach(item => {
        //         let pram = item.split("=")
        //         res[pram[0]] = pram[1]
        //     })
        //     obj = res;
        // }
        // return obj
        // let fobj = {};
        // for (let i in obj) {
        //     let str = i.replace('amp;', '');
        //     //字符过长导致生成微信小程序二维码失败解决方案
        //     switch (str) {
        //         case 'sid':
        //             str = 'shareId';
        //             break;
        //         default:
        //             break;
        //     }
        //     fobj[str] = obj[i];
        // }
        // return fobj;
    },

    //数组按照指定长度切割
    chunk(array, size) {
        //获取数组的长度，如果你传入的不是数组，那么获取到的就是undefined
        const length = array.length
        //判断不是数组，或者size没有设置，size小于1，就返回空数组
        if (!length || !size || size < 1) {
            return []
        }
        //核心部分
        let index = 0 //用来表示切割元素的范围start
        let resIndex = 0 //用来递增表示输出数组的下标

        //根据length和size算出输出数组的长度，并且创建它。
        let result = new Array(Math.ceil(length / size))
        //进行循环
        while (index < length) {
            //循环过程中设置result[0]和result[1]的值。该值根据array.slice切割得到。
            result[resIndex++] = array.slice(index, (index += size))
        }
        //输出新数组
        return result
    },
    //去左右空格;
    trim(s) {
        return s.replace(/(^\s*)|(\s*$)/g, "");
    },
    /*
     *去掉字符串中的特殊字符
     */
    excludeSpecial(s) {
        if (!s) return '';
        // 去掉转义字符
        s = s.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');
        // 去掉特殊字符
        s = s.replace(/[\@\#\r\n\$\%\^\&\*\(\)\{\}\:\"\L\<\>\?\[\]]/);
        return s;
    },
    /*
     *获取路由地址对应参数名并储存
     */
    rouName(url) {
        let rouName = this.jxUrlName(url);
        this.setStorage(rouName);
        return rouName
    },
    /*
     *获取路由地址对应参数名
     */
    jxUrlName(url) {
        let rouName = '';
        for (let i in routes) {
            if (url == routes[i].path) {
                rouName = i
            }
        }
        return rouName
    },

    /*
     *储存路由地址
     */
    setStorage(rouName) {
        if (rouName != 'commonLoginIndex' && rouName != 'daohang' && rouName != 'bindipone' && rouName !=
            'enteringExisting' &&
            rouName !=
            'enteringYesorno') {
            uni.setStorage({
                key: 'redirect',
                data: rouName,
            });
        }
    },
    /*
     *反抖
     */
    debounce(fn, delay) {
        var timer = null;
        return function() {
            var context = this;
            var args = arguments;
            clearTimeout(timer);
            timer = setTimeout(function() {
                fn.apply(context, args)
            }, delay)
        }
    },

    /* 
     * 时间戳转周几
     */
    getWeek(timestamp, format = '周') {
        let date = ((timestamp) ? new Date(timestamp * 1000) : new Date());
        var week;
        if (date.getDay() == 0) week = `${format}日`
        if (date.getDay() == 1) week = `${format}一`
        if (date.getDay() == 2) week = `${format}二`
        if (date.getDay() == 3) week = `${format}三`
        if (date.getDay() == 4) week = `${format}四`
        if (date.getDay() == 5) week = `${format}五`
        if (date.getDay() == 6) week = `${format}六`
        return week;
    },

    /*
     * 数字转周几
     */
    getNumWeek(format = '周') {
        var week;
        if (format == 7) week = `周日`
        if (format == 1) week = `周一`
        if (format == 2) week = `周二`
        if (format == 3) week = `周三`
        if (format == 4) week = `周四`
        if (format == 5) week = `周五`
        if (format == 6) week = `周六`
        return week;
    },

    /*
     *解析剩余时间
     */
    returntime(value) { // 解析剩余时间
        let data = {}
        if (value >= 0) {
            let S = (value % 60) > 9 ? parseInt((value % 60)) : '0' + parseInt((value % 60)) // 秒
            let M = parseInt(value / 60 % 60) > 9 ? parseInt(value / 60 % 60) : '0' + parseInt(value / 60 % 60) // 分
            let H = parseInt(value / 60 / 60 % 24) > 9 ? parseInt(value / 60 / 60 % 24) : '0' + parseInt(value / 60 /
                60 % 24) // 时
            let T = parseInt(value / 60 / 60 / 24) > 9 ? parseInt(value / 60 / 60 / 24) : '0' + parseInt(value / 60 /
                60 / 24) // 天
            data = {
                s: S,
                m: M,
                h: H,
                t: T,
            }
        } else {
            data = {
                s: '00',
                m: '00',
                h: '00',
                t: '00',
            }
        }
        return data
    },

    /* 
     * 时间戳转时间返回单独分开的对象
     * Y-m-d H:i:s
     * 不传format将输出{y: 2019, m: "05", d: "29", h: "06", i: "42", …}
     */
    format(timestamp, format) {
        var a, jsdate = ((timestamp) ? new Date(timestamp * 1000) : new Date());
        var pad = function(n, c) {
            if ((n = n + "").length < c) {
                return new Array(++c - n.length).join("0") + n;
            } else {
                return n;
            }
        };
        var txt_weekdays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
        var txt_ordin = {
            1: "st",
            2: "nd",
            3: "rd",
            21: "st",
            22: "nd",
            23: "rd",
            31: "st"
        };
        var txt_months = ["", "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月",
            "十月", "十一月", "十二月"
        ];
        var f = {
            // Day 
            d: function() {
                return pad(f.j(), 2)
            },
            d1: function() {
                return pad(f.j(), 1)
            },
            D: function() {
                return f.l().substr(0, 3)
            },
            j: function() {
                return jsdate.getDate()
            },
            l: function() {
                return txt_weekdays[f.w()]
            },
            N: function() {
                return f.w() + 1
            },
            S: function() {
                return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th'
            },
            w: function() {
                return jsdate.getDay()
            },
            z: function() {
                return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0
            },

            // Week 
            W: function() {
                var a = f.z(),
                    b = 364 + f.L() - a;
                var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;
                if (b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b) {
                    return 1;
                } else {
                    if (a <= 2 && nd >= 4 && a >= (6 - nd)) {
                        nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
                        return date("W", Math.round(nd2.getTime() / 1000));
                    } else {
                        return (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);
                    }
                }
            },

            // Month 
            F: function() {
                return txt_months[f.n()]
            },
            m: function() {
                return pad(f.n(), 2)
            },
            m1: function() {
                return pad(f.n(), 1)
            },
            M: function() {
                return f.F().substr(0, 3)
            },
            n: function() {
                return jsdate.getMonth() + 1
            },
            t: function() {
                var n;
                if ((n = jsdate.getMonth() + 1) == 2) {
                    return 28 + f.L();
                } else {
                    if (n & 1 && n < 8 || !(n & 1) && n > 7) {
                        return 31;
                    } else {
                        return 30;
                    }
                }
            },

            // Year 
            L: function() {
                var y = f.Y();
                return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0
            },
            //o not supported yet 
            Y: function() {
                return jsdate.getFullYear()
            },
            y: function() {
                return (jsdate.getFullYear() + "").slice(2)
            },

            // Time 
            a: function() {
                return jsdate.getHours() > 11 ? "pm" : "am"
            },
            A: function() {
                return f.a().toUpperCase()
            },
            B: function() {
                // peter paul koch: 
                var off = (jsdate.getTimezoneOffset() + 60) * 60;
                var theSeconds = (jsdate.getHours() * 3600) + (jsdate.getMinutes() * 60) + jsdate.getSeconds() +
                    off;
                var beat = Math.floor(theSeconds / 86.4);
                if (beat > 1000) beat -= 1000;
                if (beat < 0) beat += 1000;
                if ((String(beat)).length == 1) beat = "00" + beat;
                if ((String(beat)).length == 2) beat = "0" + beat;
                return beat;
            },
            g: function() {
                return jsdate.getHours() % 12 || 12
            },
            G: function() {
                return jsdate.getHours()
            },
            h: function() {
                return pad(f.g(), 2)
            },
            H: function() {
                return pad(jsdate.getHours(), 2)
            },
            i: function() {
                return pad(jsdate.getMinutes(), 2)
            },
            s: function() {
                return pad(jsdate.getSeconds(), 2)
            },
            //u not supported yet 

            // Timezone 
            //e not supported yet 
            //I not supported yet 
            O: function() {
                var t = pad(Math.abs(jsdate.getTimezoneOffset() / 60 * 100), 4);
                if (jsdate.getTimezoneOffset() > 0) t = "-" + t;
                else t = "+" + t;
                return t;
            },
            P: function() {
                var O = f.O();
                return (O.substr(0, 3) + ":" + O.substr(3, 2))
            },
            //T not supported yet 
            //Z not supported yet 

            // Full Date/Time 
            c: function() {
                return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P()
            },
            //r not supported yet 
            U: function() {
                return Math.round(jsdate.getTime() / 1000)
            }
        };
        if (!format) {
            return {
                y: f.Y(),
                m: f.m(),
                d: f.d(),
                h: f.h(),
                i: f.i(),
                s: f.s(),
                H: f.H(),
                l: f.l(),
                F: f.F(),
                m1: f.m1(),
                d1: f.d1()
            }
        }
        return format.replace(/[\\]?([a-zA-Z])/g, function(t, s) {
            let ret;
            if (t != s) {
                // escaped 
                ret = s;
            } else if (f[s]) {
                // a date function exists 
                ret = f[s]();
            } else {
                // nothing special 
                ret = s;
            }
            return ret;
        });
    },


    /* 
     * 合并对象
     */
    hebignObj(obj1, obj2) {
        let obj = {};
        for (let i in obj2) {
            if (obj2[i] === "" || obj2[i] === undefined || obj2[i] === "undefined" || obj2[i] === null || obj2[i] ===
                "null") {
                delete obj2[i];
            }
        }
        Object.assign(obj, obj1, obj2);
        return obj
    },

    //返回变量类型
    gettype(data) {
        var pro = Object.prototype.toString;
        return pro.call(data);
    },

    /* 
     * obj 转 params字符串参数  
     * 例子：{a:1,b:2} => a=1&b=2
     */
    objParseParam(obj) {
        let paramsStr = "";
        if (obj instanceof Array) return paramsStr;
        if (!(obj instanceof Object)) return paramsStr;
        for (let key in obj) {
            paramsStr += `${key}=${obj[key]}&`;
        }
        return paramsStr.substring(0, paramsStr.length - 1);
    },

    /* 
     * obj 转 路由地址带参数
     * 例子：obj => {a:1,b:2} => /pages/index/index?a=1&b=2
     * path => pages/index/index
     */
    objParseUrlAndParam(path, obj) {
        let url = path || "/";
        let paramsStr = "";
        if (obj instanceof Array) return url;
        if (!(obj instanceof Object)) return url;
        paramsStr = this.objParseParam(obj);
        paramsStr && (url += "?");
        url += paramsStr;
        return url;
    },

    /* 
     * 获取url字符串参数
     */
    getRequestParameters(locationhref) {
        let href = locationhref || "";
        let theRequest = new Object();
        let str = href.split("?")[1];
        if (str != undefined) {
            let strs = str.split("&");
            for (let i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
            }
        }
        return theRequest;
    },

    /* 
     * 银行卡每四位空格
     */
    formatCardNo(cardNo) {
        cardNo += "";
        return cardNo.replace(/\s/g, '').replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ');
    },

    /**
     * 乘法，解决js精度损失问题
     * @param {*} arg1 
     * @param {*} arg2 
     */
    accMul(arg1, arg2) {
        arg1 = arg1 || 0;
        var m = 0,
            s1 = arg1.toString(),
            s2 = arg2.toString();
        try {
            m += s1.split(".")[1].length
        } catch (e) {}
        try {
            m += s2.split(".")[1].length
        } catch (e) {}
        return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
    },
    /**
     * 去除数组空元素
     */
    removeEmptyArrayEle(arr) {
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] == undefined) {
                arr.splice(i, 1);
                i = i - 1; // i - 1 ,因为空元素在数组下标 2 位置，删除空之后，后面的元素要向前补位，
                // 这样才能真正去掉空元素,觉得这句可以删掉的连续为空试试，然后思考其中逻辑
            }
        }
        return arr;
    },

    /**
     * 个位数转两位字符串
     */
    forMatNum(num) {
        return num < 10 ? '0' + num : num + '';
    },
    /**
     * 生成时间时间选择插件使用
     */
    initDays(year, month) {
        let totalDays = new Date(year, month, 0).getDate();
        let dates = [];
        for (let d = 1; d <= totalDays; d++) {
            dates.push(this.forMatNum(d));
        };
        return dates;
    },
    /**
     * 生成时间时间选择插件使用
     */
    initPicker(start, end, mode = "date", step) {
        let initstartDate = new Date(start);
        let endDate = new Date(end);
        let startYear = initstartDate.getFullYear();
        let startMonth = initstartDate.getMonth();
        let endYear = endDate.getFullYear();
        let years = [],
            months = [],
            days = [],
            hours = [],
            minutes = [],
            seconds = [];
        let totalDays = new Date(startYear, startMonth, 0).getDate();
        for (let s = startYear; s <= endYear; s++) {
            years.push(s + '');
        };
        for (let m = 1; m <= 12; m++) {
            months.push(this.forMatNum(m));
        };
        for (let d = 1; d <= totalDays; d++) {
            days.push(this.forMatNum(d));
        }
        for (let h = 0; h < 24; h++) {
            hours.push(this.forMatNum(h));
        }
        for (let m = 0; m < 60; m += step * 1) {
            minutes.push(this.forMatNum(m));
        }
        for (let s = 0; s < 60; s++) {
            seconds.push(this.forMatNum(s));
        }
        switch (mode) {
            case "date":
                return {
                    years,
                    months,
                    days
                }
                break;
            case "yearMonth":
                return {
                    years,
                    months
                }
                break;
            case "dateTime":
                return {
                    years,
                    months,
                    days,
                    hours,
                    minutes,
                    seconds
                }
                break;
            case "time":
                return {
                    hours,
                    minutes,
                    seconds
                }
                break;
        }
    },
    /*
     *合并对象数组
     */
    extend(des, src, override) {
        if (src instanceof Array) {
            for (var i = 0, len = src.length; i < len; i++)
                this.extend(des, src[i], override);
        }
        for (var i in src) {
            if (override || !(i in des)) {
                des[i] = src[i];
            }
        }
        // console.log(src instanceof Array);
        return des;
    },
    /*
     *阿拉伯数字转换为简写汉字
     */
    Arabia_To_SimplifiedChinese(Num) {
        for (let i = Num.length - 1; i >= 0; i--) {
            Num = Num.replace(",", "") //替换Num中的“,”
            Num = Num.replace(" ", "") //替换Num中的空格
        }
        if (isNaN(Num)) { //验证输入的字符是否为数字
            //alert("请检查小写金额是否正确");
            return;
        }
        //字符处理完毕后开始转换，采用前后两部分分别转换
        let part = String(Num).split(".");
        let newchar = "";
        //小数点前进行转化
        for (let i = part[0].length - 1; i >= 0; i--) {
            if (part[0].length > 10) {
                //alert("位数过大，无法计算");
                return "";
            } //若数量超过拾亿单位，提示
            let tmpnewchar = ""
            let perchar = part[0].charAt(i);
            switch (perchar) {
                case "0":
                    tmpnewchar = "零" + tmpnewchar;
                    break;
                case "1":
                    tmpnewchar = "一" + tmpnewchar;
                    break;
                case "2":
                    tmpnewchar = "二" + tmpnewchar;
                    break;
                case "3":
                    tmpnewchar = "三" + tmpnewchar;
                    break;
                case "4":
                    tmpnewchar = "四" + tmpnewchar;
                    break;
                case "5":
                    tmpnewchar = "五" + tmpnewchar;
                    break;
                case "6":
                    tmpnewchar = "六" + tmpnewchar;
                    break;
                case "7":
                    tmpnewchar = "七" + tmpnewchar;
                    break;
                case "8":
                    tmpnewchar = "八" + tmpnewchar;
                    break;
                case "9":
                    tmpnewchar = "九" + tmpnewchar;
                    break;
            }
            switch (part[0].length - i - 1) {
                case 0:
                    tmpnewchar = tmpnewchar;
                    break;
                case 1:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "十";
                    break;
                case 2:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "百";
                    break;
                case 3:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "千";
                    break;
                case 4:
                    tmpnewchar = tmpnewchar + "万";
                    break;
                case 5:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "十";
                    break;
                case 6:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "百";
                    break;
                case 7:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "千";
                    break;
                case 8:
                    tmpnewchar = tmpnewchar + "亿";
                    break;
                case 9:
                    tmpnewchar = tmpnewchar + "十";
                    break;
            }
            newchar = tmpnewchar + newchar;
        }
        //替换所有无用汉字，直到没有此类无用的数字为止
        while (newchar.search("零零") != -1 || newchar.search("零亿") != -1 || newchar.search("亿万") != -1 || newchar.search(
                "零万") !=
            -1) {
            newchar = newchar.replace("零亿", "亿");
            newchar = newchar.replace("亿万", "亿");
            newchar = newchar.replace("零万", "万");
            newchar = newchar.replace("零零", "零");
        }
        //替换以“一十”开头的，为“十”
        if (newchar.indexOf("一十") == 0) {
            newchar = newchar.substr(1);
        }
        //替换以“零”结尾的，为“”
        if (newchar.length == 1) return newchar;
        if (newchar.lastIndexOf("零") == newchar.length - 1) {
            newchar = newchar.substr(0, newchar.length - 1);
        }
        return newchar;
    },
    //去掉汉字  
    RemoveChinese(strValue) {
        if (strValue != null && strValue != "") {
            var reg = /[\u4e00-\u9fa5]/g;
            return strValue.replace(reg, "");
        } else
            return "";
    },
    // 动态创建a标签下载文件
    downLoaderFileA(downLoadUrl) {
        var a = document.createElement('a');
        a.href = downLoadUrl;
        a.download = downLoadUrl;
        a.click();
        return false;
    },
    ...dataFunction
}
